package com.haojiang.mh.service.event

import com.haojiang.mh.utils.KLog

/**
 * 发送事件
 */
class OneEvent {

    var type = 0 //事件类型，参照Const-Event
    private var paramMap: MutableMap<String, Any>? = null //发送参数

    constructor(type: Int) {
        this.type = type
        this.paramMap = null
        KLog.v("OneEvent---->$type")
    }

    constructor(type: Int, text: String) {
        this.type = type
        if (paramMap == null) paramMap = HashMap()
        paramMap!!["param_value"] = text
    }

    constructor(type: Int, value: Int) {
        this.type = type
        if (paramMap == null) paramMap = HashMap()
        paramMap!!["param_value"] = value
    }

    constructor(type: Int, paramMap: MutableMap<String, Any>) {
        this.type = type
        this.paramMap = paramMap
    }

    fun getParamMap(): MutableMap<String, Any>? {
        return paramMap
    }

    fun getStringValue(): String {
        return if (paramMap.isNullOrEmpty()) {
            ""
        } else {
            paramMap!!["param_value"] as String
        }
    }

    fun getIntValue(): Int {
        return if (paramMap.isNullOrEmpty()) {
            -1
        } else {
            paramMap!!["param_value"] as Int
        }
    }

    override fun toString(): String {
        return "OneEvent{" +
                "type=" + type +
                ", paramMap=" + paramMap +
                '}'.toString()
    }
}
